/*
This is the mastercode file for the replication of: Place-based Campaigning in JoP

HELP:
- you need to install "project" in stata: ssc install project 
- after that you type: project, setup and select this master file
project , setmaster("folder") textlog
- then you can rebuild the entire analyses by typing: project xyz, build


*/ 

*Stata MP Version 17.0 // in case Stata's syntax changes in future versions

* directory definitions 

	project, doinfo
	global pdir "`r(pdir)'"							// the project's main dir.
	global dofile "`r(dofile)'"						// do-file's stub name
	global data_original = "$pdir/data_original"  //data directory for coded data 
	global data_coded = "$pdir/data_coded"  //data directory for coded data 
	global figures = "$pdir/results/figures"  //data directory for figures
	global tables = "$pdir/results/tables"  //data directory for tables

* Common settings

        set more off
        set varabbrev off  // less confusing
        set linesize 132   // use 7pt font for printing

* packages to install: 
foreach package in CODEBOOKOUT spmap ebalance shp2dta mif2dta egen fre coefplot gsort ivreghdfe reghdfe ranktest erepost tuples renvars revrs regsave project psmatch2 freqindex estout ivregress ivreg2 putexcel{
      capture which `package'
      if _rc==111 ssc install `package'
}

* Sometimes issues with FE of reghdfe. Then use: 
    reghdfe, compile

* Run do-files

    cls
*
    //prepare the regional level data:
    project, do(code/do/05_prepare_regional.do)

*
    //prepare the individual level data:
    project, do(code/do/06_prepare_individual.do)

*
    //prepare shapefile and data for maps:
    project, do(code/do/07_prepare_maps.do)

*
    //prepare ITANES 1996 for independence tests:
    project, do(code/do/08_prepare_independence.do)

*
    //analyze the regional level data:
    project, do(code/do/09_analysis_regional.do)

*
    //analyze the individual level data:
    project, do(code/do/10_analysis_individual.do)

*
    //cleanings to ensure that next replication run will be successful:
    project, do(code/do/11_cleanings.do)
    